import 'package:flutter/material.dart';
import 'package:my_app/conponate/expence_search.dart';
import 'package:my_app/conponate/user_info.dart';
import 'package:my_app/tools/camera_or_gallery.dart';
import '../pages/swiper.dart';
// import '../pages/commend_page.dart';
import '../tools/http_server.dart';
import 'searching_content.dart';
import '../pages/draw_layout.dart';
import 'record_page.dart';


class SearchingCard extends StatefulWidget {
  const SearchingCard({Key? key}) : super(key: key);
  @override
  _SearchingCardState createState() => _SearchingCardState();
}


class _SearchingCardState extends State<SearchingCard> {
  // List tabs = ["Home Page"];
  // late TabController _TabController;
  // int _index = 0;

  // @override
  // void initState() {
  //   // TODO: implement initState
  //   // _TabController = new TabController(
  //   //     initialIndex: _index, length: tabs.length, vsync: this
  //   // );
  //   // _TabController.addListener(() {
  //   //   setState(() {
  //   //     _index = _TabController.index;
  //   //   });
  //   // });
  //   super.initState();
  // }

  // @override
  // void dispose() {
  //   // TODO: implement dispose
  //   _TabController.dispose();
  //   super.dispose();
  // }

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      // backgroundColor: Colors.black87,
        appBar: AppBar(
          backgroundColor: Colors.blueGrey,
          leading: Builder(
              builder: (BuildContext context){
                return IconButton(
                    icon: Icon(Icons.view_headline_rounded),
                    onPressed: (){
                      Scaffold.of(context).openDrawer();
                    }
                );
              }
          ),
          title: Text(
            "主页",
          ),
          actions: [
            IconButton(
                onPressed: () {
                  showSearch(context: context, delegate: SearchBarDelegate());
                },
                icon: Icon(Icons.search)
            ),
          ],
          centerTitle: true,

          elevation: 5.0,
          // 阴影
          // bottom: TabBar(
          //   controller: _TabController,
          //   tabs: tabs
          //       .map((e) => Tab(
          //     text: e,
          //   ))
          //       .toList(),
          // ),
        ),
        drawer: DrawLayout(),
        body: FirstView(),
        // widget.widgets[_index],
        // TabBarView(
        //   children: widget.widgets,
        //   controller: _TabController,
        // )

    );
  }

}

class FirstView extends StatefulWidget {
  const FirstView({Key? key}) : super(key: key);

  @override
  _FirstViewState createState() => _FirstViewState();
}

class _FirstViewState extends State<FirstView> {

  String rubbishType = "";
  String rubbishName = "";

  List<Widget> tiles = [];

  @override
  Widget build(BuildContext context) {
    TextEditingController _searchingController = new TextEditingController();
    GlobalKey _formKey = new GlobalKey<FormState>();
    bool _searchAutoFocus = false;

    return
      CustomScrollView(
        scrollDirection: Axis.vertical,
        slivers: <Widget>[
      SliverList(
      delegate: new SliverChildListDelegate(
      [
      // Column(
      // children: [
        SizedBox(height: 10,),
        SwiperPage(),
        Padding(padding: EdgeInsets.only(left :50,  right :50,),
          child: TextField(
            decoration: InputDecoration(
              focusedBorder: UnderlineInputBorder(
                borderSide: BorderSide(color: const Color(0xffb6ad90),),
              ),
              hintText: "请在此输入想搜索的物品……",
              hintStyle: TextStyle(
                color: const Color(0xffb6ad90),),
              suffixIcon: Icon(Icons.search,
                color:const Color(0xffb6ad90)),
            ),
            onTap: (){
              showSearch(context: context, delegate: SearchBarDelegate());
            },
            autofocus: _searchAutoFocus,
            controller: _searchingController,
            onChanged: (v){
              this.rubbishName = v;
            },
          ),
        ),
        SizedBox(
          height: 10,
        ),
        IconButton(
          icon: Icon(Icons.camera,
          color: const Color(0xffb6ad90),),
          onPressed: () {
            // todo: 调用相机，获取图像
            // todo: 对图像进行编码，作为参数传递给postImg()函数
            // CameraOrGallery.openGallery();
            Navigator.of(context).push(
                MaterialPageRoute(
                    builder: (context) {
                      return ImagePickerWidget();
                    }
                )
            );
          },
        ),
        RecordItems(),
      ],
    ),),],);
  }
}

